package com.hundsun.s3.common.util;

import com.hundsun.s3.dto.DataObj;
import com.hundsun.s3.dto.PieDto;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * com.hundsun.s3.platform.backstage.common.util
 *
 * @Description:
 * @Author: yangjun23614
 * @Date: Created in 14:08 2018/3/1
 * V1.0 14:08 2018/3/1
 */
public class ChartUtils {
    /**
     * @Description: 获得int[]中最大数
     * @param:
     * @return:
     * @Author: yangjun23614
     * @Date: 14:10 2018/3/1
     * V1.0
     */
    public static int getMaxInt(int[] arr){
        int max = 0;
        for (int i : arr) {
            if(max < i){
                max = i;
            }
        }
        return max;
    }

    /**
     * @Description: 获取当前年份
     * @param:
     * @return: int
     * @Author: yangjun23614
     * @Date: 14:45 2018/3/1
     * V1.0
     */
    public static int getThisYear(){
        Calendar now = Calendar.getInstance();
        int thisYear = now.get(Calendar.YEAR);//获取当前年份
        return thisYear;
    }

    /**
     * @Description:
     * @param: 
     * @return:  
     * @Author: yangjun23614
     * @Date: 12:59 2018/3/6
     * V1.0 
     */
    public static int getThisYearAndMonth(){
        Calendar now = Calendar.getInstance();
        int thisYear = now.get(Calendar.YEAR);//获取当前年份
        int thisMonth = now.get(Calendar.MONTH);
        int thisYearMonth = thisYear*100 + thisMonth;
        return thisYearMonth;
    }

    /**
     * @Description: 获取List<Map<String, String>>中list第一条map的数据的所有value的值
     *  适用于结果集只有一行并且value值为int类型的情况
     * @param: [ List<Map<String, String>> , int[]  ]
     * @return: int[]
     * @Author: yangjun23614
     * @Date: 13:59 2018/3/2
     * V1.0
     */
    public static void getValuesInListMap(List<Map<String, String>> list,int[] datas){
        if(list.size() != 0){
            Map<String,String> map = list.get(0);
            if(map.size() != 0){
                int i = 0;
                for(String data:map.values()){
                    datas[i] = Integer.parseInt(data);
                    i++;
                }
            }
        }
    }

    /**
     * @Description: 将数据封装为y轴数据
     * @param: String[] legendData,List<int[]> datas,List<DataObj> list
     * @return: void
     * @Author: yangjun23614
     * @Date: 15:41 2018/3/5
     * V1.0
     */
    public static void setStackedLineYData(String[] legendData,List<int[]> datas,List<DataObj> list){
        int j = 0;
        for(String item:legendData){
            DataObj obj = new DataObj();
            obj.setName(item);
            obj.setData(datas.get(j));
            list.add(obj);
            j++;
        }
    }

    /**
     * @Description: 将数据封装到
     * @param: String[] legendData,List<PieDto> list,int[] data
     * @return: void
     * @Author: yangjun23614
     * @Date: 16:20 2018/3/5
     * V1.0
     */
    public static void setPieData(String[] legendData, List<PieDto> list, int[] data){
        int i = 0;
        for(String item:legendData){
            PieDto obj = new PieDto();
            obj.setName(item);
            obj.setValue(data[i]);
            list.add(obj);
            i++;
        }
    }
}
